package org.southyin.securitysamples.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.southyin.securitysamples.mapper.CustomerMapper;
import org.southyin.securitysamples.model.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CustomerService {
    @Autowired
    CustomerMapper customerMapper;

    public PageInfo listCustomers(String keyWords, Integer pageNum, Integer pageSize) {
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<Customer> customers = customerMapper.listCustomers(keyWords);
        PageInfo<Customer> pageInfo = new PageInfo<>(customers);
        return pageInfo;
    }

    public int multiInsertCustomers(List<Customer> customerList) {
        return customerMapper.multiInsertCustomers(customerList);
    }
}
